package src.com.ny.Dao.impl;

import src.com.ny.entity.Product;
import src.com.ny.entity.Student;
import src.com.ny.until.SqlConnection;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class ProductDaoImpl  implements ProductDao {
        Connection  connection = SqlConnection.getCon();
        public ProductDaoImpl () throws SQLException, ClassCastException, ClassNotFoundException {
        }

    @Override
    public int add(Student student) throws SQLException {
        return 0;
    }

    @Override
    public List<Product> findAllProducts() {
        return null;
    }

    @Override
        public List<Product> findAllProduct() throws SQLException {
            List<Product> productList = new ArrayList<>();
            String sql = "select * from product";
            PreparedStatement preparedStatement = connection.prepareStatement(sql);
            ResultSet resultSet = preparedStatement.executeQuery();

            while (resultSet.next()) {
            Product product = new Product();
            product.setProduct_id(resultSet.getInt("product_id"));
            product.setName(resultSet.getString("name"));
            product.setPrice(resultSet.getDouble("price"));
            product.setStock(resultSet.getInt("stock"));
            product.setCategory(resultSet.getString("category"));
            product.setDescription(resultSet.getString("description"));
            productList.add(product);
            }
            return productList;

        }


    }

